package com.kanesoft.android.gdx.actors.fight;

import com.badlogic.gdx.math.Vector2;
import com.kanesoft.android.gdx.widgets.sprites.SpriteInfo;

public class FighterHittenByFallingPunch extends FightActorStateMachine {
  
    private FightActorObject fightActor;
    private boolean alreadyUpdated;
    
    public FighterHittenByFallingPunch(SpriteInfo stateSpriteInfo, FightActorObject actor) {
        super(stateSpriteInfo, actor);
        fightActor = actor;
    }

    @Override
    public boolean OnEnter() {
        
        if (fightActor.getActorState() != null) {
            if (fightActor.getActorState().equals(fightActor.hittenByFallingPunch)) return false;
        }
        alreadyUpdated = false;
        
        actorSprite.setAnimationInLoop(false);
        actorSprite.setSpriteInfo(stateSpriteInfo);

        return true;
    }

    @Override
    public boolean OnUpdate() {
        if (alreadyUpdated) return true;
        alreadyUpdated = true;
        
        fightActor.decreseLifePower(5);
        
        fightActor.getSensorFixture().setFriction(0.2f);

        Vector2 objPosition = fightActor.getActorBody().getPosition();
        
        if (  fightActor.getHorizontalFlip() == false) fightActor.getActorBody().applyLinearImpulse(-fightActor.getHitAceleration(), 0,
                objPosition.x, objPosition.y);
        if (fightActor.getHorizontalFlip() == true) fightActor.getActorBody().applyLinearImpulse(fightActor.getHitAceleration(), 0,
                objPosition.x, objPosition.y);
        
        return true;
    }

    @Override
    public String getStateName() {
        return "HittenByKick";
    }

}
